<template>
  <el-cascader
    :show-all-levels="false"
    :options="tree"
    :props="{ value:'id',label:'name',checkStrictly: true}"
    v-model="val"
    :disabled="disabled"
    @change="$emit('change',$event[$event.length-1])"
  />
</template>
<script>
//     @change="$emit('change',$event[$event.length-1])"

// import name from "./name";
export default {
  // components: { name},
  props: {
    value: { default: false },
    disabled: { default: false }
  },
  watch: {
    "gd.userType"() {
      this.setTree();
    },
    data() {
      this.setTree();
    }
  },
  data() {
    return {
      tree: [],
      val: []
    };
  },
  // computed() {return{}},
  created() {
    this.setTree();
  },
  methods: {
    tst(a, b) {
      console.log(this.$cp(a));
      this.$emit('change',a);
    },
    setTree() {
      this.tree = this.$gd.userType.arr2tree();
      // console.log(this.$cp(this.tree));
      if (this.value) {
        let d = this.$gd.userType.v2item(this.value);
        this.val = [];
        while (d) {
          this.val.unshift(d.id);
          d = this.$gd.userType.v2item(d.pid);
        }
      }
    }
  }
};
</script>

<style lang="less" scoped>
</style>
